package com.education.welco.controller.app;


import com.education.common.core.BaseController;
import com.education.common.utils.ApiReturnObject;
import com.education.welco.pojo.LResources;
import com.education.welco.pojo.SCatalogPreview;
import com.education.welco.pojo.SResources;
import com.education.welco.service.ISResourcesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 学校课程资源 信息操作处理
 *
 * @author d
 * @date 2020-05-08
 */
@Api(tags = {"APP-学校课程--资源"})
@RestController
@RequestMapping("/app/sResources")
public class AppSResourcesController extends BaseController {

    @Autowired
    private ISResourcesService resourcesService;


    @ApiOperation(value = "学校课程--资源接口", httpMethod = "GET")
    @GetMapping("/selectByResources")
    public ApiReturnObject selectByResources1(Integer catalogId, Integer classId) {
        if (null != catalogId) {
           //List<List<SResources>> list = new ArrayList<>();
            //图片
            Map<String,Object> map=new HashMap<>();
            SResources rImg = new SResources();
            rImg.setRCatalogid(catalogId);//这里catalogid是parentid
            rImg.setType("4");
            rImg.setIsStu("1");
            rImg.setClassId(classId);
            List<SResources> list1 = resourcesService.selectSResourcesList(rImg);
          //  list.add(list1);
            map.put("tp",list1);
            //教学课件
            SResources rCourseware = new SResources();
            rCourseware.setRCatalogid(catalogId);
            rCourseware.setType("1");
            rCourseware.setIsStu("1");
            rCourseware.setClassId(classId);
            List<SResources> list2 = resourcesService.selectSResourcesList(rCourseware);
            //list.add(list2);
            map.put("jxkj",list2);

            //技术文档  documents
            SResources rDocuments = new SResources();
            rDocuments.setRCatalogid(catalogId);
            rDocuments.setType("2");
            rDocuments.setIsStu("1");
            rDocuments.setClassId(classId);
            List<SResources> list3 = resourcesService.selectSResourcesList(rDocuments);
            //list.add(list3);
            map.put("jswd",list3);

            //教学笔记  notes
            SResources rNotes = new SResources();
            rNotes.setRCatalogid(catalogId);
            rNotes.setType("3");
            rNotes.setIsStu("1");
            rNotes.setClassId(classId);
            List<SResources> list4 = resourcesService.selectSResourcesList(rNotes);

            map.put("jxbj",list4);

           // list.add(list4);
            return new ApiReturnObject("200", "查询成功", map);
        } else {
            return new ApiReturnObject("201", "catalogId为空", "catalogId为空");
        }
    }



    @ApiOperation(value = "学校课程--虚拟教学接口 安卓", httpMethod = "GET")
    @GetMapping("/selectByFlash")
    public ApiReturnObject selectByFlash(Integer catalogId) {
        if (catalogId == null) {
            return new ApiReturnObject("201", "catalogId为空", "catalogId为空");
        } else {
            List<List<SResources>> list = new ArrayList<>();

            //3D视频
            SResources sResources3D = new SResources();
            //这里catalogid是parentid
            sResources3D.setRCatalogid(catalogId);
            sResources3D.setType("6");
            sResources3D.setIsStu("1");
            List<SResources> lise1 = resourcesService.selectSResourcesList(sResources3D);
            list.add(lise1);
            //flash视频
            SResources sResourcesFlash = new SResources();
            sResourcesFlash.setRCatalogid(catalogId);
            sResourcesFlash.setType("7");
            sResourcesFlash.setIsStu("1");
            List<SResources> lise2 = resourcesService.selectSResourcesList(sResourcesFlash);
            list.add(lise2);
            return new ApiReturnObject("200", "查询成功",list.size(),list);
        }
    }


    @ApiOperation(value = "学校课程--虚拟教学接口 IOS", httpMethod = "GET")
    @GetMapping("/selectByFlash2IOS")
    public ApiReturnObject selectByFlash2IOS(Integer catalogId, Integer classId) {
        if (catalogId == null) {
            return new ApiReturnObject("201", "catalogId为空", "catalogId为空");
        } else {

            //3D视频
            SResources sResources3D = new SResources();
            sResources3D.setRCatalogid(catalogId);//这里catalogid是parentid
            sResources3D.setType("6");
            sResources3D.setIsStu("1");
            sResources3D.setClassId(classId);
            List<SResources> list = resourcesService.selectSResourcesList(sResources3D);

            //flash视频
            SResources sResourcesFlash = new SResources();
            sResourcesFlash.setRCatalogid(catalogId);
            sResourcesFlash.setType("7");
            sResourcesFlash.setIsStu("1");
            sResourcesFlash.setClassId(classId);
            List<SResources> lise2 = resourcesService.selectSResourcesList(sResourcesFlash);
            //把url设置到flash
            if (lise2.size() != 0) {
                for (SResources lResources : lise2) {
                    lResources.setFlash(lResources.getRUrl());
                }
            }
            //如果没有3D 就直接返回flash
            if (list.size() == 0){
                return new ApiReturnObject("200", "查询成功",lise2.size(),lise2);
            }


            if (lise2.size() != 0 && list.size() != 0) {
                //3D
                for (SResources lResource : list) {
                    //flash
                    for (SResources lResources : lise2) {
                        lResource.setFlash(lResources.getRUrl());
                    }
                }
            }
            return new ApiReturnObject("200", "查询成功",list.size(),list);
        }
    }

}